<template>
  <div 
    :class="[
      'bx-option',
      {
        'bx-option--selected': isSelected,
        'bx-option--disabled': disabled
      }
    ]"
    @click="handleClick"
  >
    <div class="bx-option__content">
      <slot>{{ label }}</slot>
    </div>
    
    <BxIcon 
      v-if="isSelected"
      name="check"
      class="bx-option__check"
    />
  </div>
</template>

<script>
import { computed, inject } from 'vue'
import BxIcon from '../basic/BxIcon.vue'

export default {
  name: 'BxOption',
  components: {
    BxIcon
  },
  props: {
    value: {
      type: [String, Number],
      required: true
    },
    label: {
      type: String,
      required: true
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  setup(props) {
    const select = inject('bx-select', {})

    const isSelected = computed(() => {
      return select.selectedValues?.includes(props.value) || false
    })

    const handleClick = () => {
      if (props.disabled) return
      select.handleSelect?.(props.value)
    }

    return {
      isSelected,
      handleClick
    }
  }
}
</script>

<style scoped>
.bx-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  cursor: pointer;
  transition: all var(--bx-transition-medium);
  color: var(--bx-text-primary);
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  z-index: 1;
}

.bx-option:hover {
  background: var(--bx-glass-bg-hover);
}

.bx-option--selected {
  background: rgba(0, 122, 255, 0.1);
  color: var(--bx-text-primary);
}

.bx-option--disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.bx-option--disabled:hover {
  background: transparent;
}

.bx-option__content {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bx-option__check {
  font-size: 14px;
  color: rgba(0, 122, 255, 0.8);
  margin-left: 8px;
  flex-shrink: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .bx-option {
    padding: 6px 12px;
    font-size: 13px;
  }
  
  .bx-option__check {
    font-size: 13px;
  }
}
</style>

